﻿using System;
using System.Data.Linq;
using System.Linq;

namespace StreetPacMan.Server
{
    public interface IGamesStorage
    {
        Game GetGameByName(string gameName);
    }
    public class GamesStorage : IGamesStorage
    {
        private readonly IConnectionProvider _ConnectionProvider;
        private readonly IGameRules _Rules;

        public GamesStorage(IConnectionProvider connectionProvider, IGameRules rules)
        {
            _ConnectionProvider = connectionProvider;
            _Rules = rules;
        }

 

        public Game GetGameByName(string gameName)
        {
            using (var dbConnection = _ConnectionProvider.GetConnection())
            using (var pacManDataContext = new PacManDataContext(dbConnection))
            {
                return pacManDataContext.Games.Where(x => x.Name == gameName).FirstOrDefault();
            }
        }
    }
}